home *** CD-ROM | disk | FTP | other *** search
/ Hobby PC 11 / Hobby PC 11.iso / lotuspro / compnent / ltssl30.lss < prev    next >
Text File  |  1996-03-13  |  23KB  |  808 lines

  1. '--------------------------------------------------------------------------
  2. '
  3. '    File:         LTSSL30.LSS
  4. '    Module:    Sample Function Libraries - Windows 3.1 interfaces
  5. '    Created:    07/12/94
  6. '
  7. '    Copyright (c) 1994-95 Lotus Development Corporation
  8. '
  9. '    Description: This file contains the following sample 
  10. '        LotusScript Windows Functions:
  11. '    
  12. '        GetTempDirectory
  13. '        GetWinDirectory
  14. '        WindowsHelp
  15. '        GetProfInteger
  16. '        GetProfString
  17. '        WriteProfInteger
  18. '        WriteProfString
  19. '
  20. '        AppClose
  21. '        AppGetAppCount
  22. '        AppGetAppNames
  23. '        AppGetHWnd
  24. '        AppGetWindowPos
  25. '        AppHide
  26. '        AppShow
  27. '        AppIsRunning
  28. '        AppIsVisible
  29. '        AppMaximize
  30. '        AppMinimize
  31. '        AppMove
  32. '        AppRestore
  33. '        AppSize
  34. '        AppSendMessage
  35. '
  36. '        FormatDate
  37. '        DateDiff
  38. '        Pause
  39. '        ProperCase
  40. '        Repeat
  41. '        Str_Word
  42. '        Log10
  43. '
  44. '    Disclaimer:
  45. '        The sample LotusScript functions are provided 
  46. '        as code examples that provide useful functionality
  47. '        to LotusScript programmers.  lotus makes no promise
  48. '        or guarantee with respect to the use of these
  49. '        functions.  Users can use the library at their own risk.
  50. '
  51. '--------------------------------------------------------------------------
  52.  
  53. option declare
  54. option compare nocase
  55.  
  56. '--------------------------------------------------------------------------
  57. ' Windows functions/constants
  58. '
  59. ' Culled from windows.h, rather than including the whole huge file.
  60. '--------------------------------------------------------------------------
  61.  
  62. '------------------------------------------
  63. ' WinHelp
  64. '------------------------------------------
  65.  
  66. public Const HELP_CONTENTS        = &H3    ' Display index.
  67. public Const HELP_FORCEFILE    = &H9 ' Ensure that correct file is displayed.
  68. public Const HELP_HELPONHELP    = &H4    ' Display "Using Help"    
  69. public Const HELP_QUIT            = &H2 ' Help no longer needed.
  70.  
  71. '------------------------------------------
  72. ' GetWindow
  73. '------------------------------------------
  74.  
  75. public Const GW_HWNDFIRST        = 0
  76. public Const GW_HWNDLAST        = 1
  77. public Const GW_HWNDNEXT        = 2
  78. public Const GW_HWNDPREV        = 3
  79. public Const GW_OWNER            = 4
  80. public Const GW_CHILD            = 5
  81.  
  82. '------------------------------------------
  83. ' GetWindowRect
  84. '------------------------------------------
  85.  
  86. Type RECT
  87.     left As Integer
  88.     top As Integer
  89.     right As Integer
  90.     bottom As Integer
  91. End Type
  92.  
  93. '------------------------------------------
  94. ' ShowWindow 
  95. '------------------------------------------
  96.  
  97. public Const SW_HIDE                 = 0
  98. public Const SW_NORMAL                 = 1
  99. public Const SW_MAXIMIZE             = 3
  100. public Const SW_SHOW                 = 5
  101. public Const SW_MINIMIZE             = 6
  102. public Const SW_RESTORE             = 9
  103.  
  104. '------------------------------------------
  105. ' SetWindowPos
  106. '------------------------------------------
  107.  
  108. public Const SWP_NOSIZE         = &H1
  109. public Const SWP_NOMOVE         = &H2
  110. public Const SWP_NOZORDER         = &H4
  111.  
  112. '--------------------------------------------------------------------------
  113. ' External Function Declarations
  114. '
  115. ' Rather than include a monster header file with every Windows function
  116. ' in it, we just take what we need.
  117. '--------------------------------------------------------------------------
  118.  
  119. Declare Function GetWindowsDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  120. Declare Function GetProfileInt Lib "Kernel" (ByVal lpSection As String, ByVal lpEntry As String, ByVal nDefault As Integer) As Integer
  121. Declare Function GetProfileString Lib "Kernel" (ByVal lpSection As String, ByVal lpEntry As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer) As Integer
  122. Declare Function GetPrivateProfileInt Lib "Kernel" (ByVal lpSection As String, ByVal lpEntry As String, ByVal nDefault As Integer, ByVal lpFileName As String) As Integer
  123. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  124. Declare Function WriteProfileString Lib "Kernel" (ByVal lpSection As String, ByVal lpEntry As String, ByVal lpNewString As String) As Integer
  125. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpSection as String, ByVal lpEntry As String, ByVal lpNewString As String, ByVal lpFileName As String ) As Integer
  126. Declare Function WinHelp Lib "User" (ByVal hWnd As Integer, ByVal lpHelpFile As String, ByVal wCommand As Integer, dwData As Any) As Integer
  127. Declare Function GetWindow Lib "User" (ByVal hWnd As Integer, ByVal wCmd As Integer) As Integer
  128. Declare Function GetDesktopWindow Lib "User" () As Integer
  129. Declare Function GetWindowText Lib "User" (ByVal hWnd As Integer, ByVal lpString As String, ByVal aint As Integer) As Integer
  130. Declare Function GetNextWindow Lib "User" (ByVal hWnd As Integer, ByVal wFlag As Integer) As Integer
  131. Declare Function IsWindowVisible Lib "User" (ByVal hWnd As Integer) As Integer
  132. Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
  133. Declare Sub GetWindowRect Lib "User" (ByVal hWnd As Integer, lpRect As RECT)
  134. Declare Function ShowWindow Lib "User" (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer
  135. Declare Function SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
  136.  
  137.  
  138. '--------------------------------------------------------------------------
  139. '
  140. ' Implementation
  141. '
  142. '--------------------------------------------------------------------------
  143.  
  144. Public Function GetWinDirectory() as String
  145.  
  146. '--------------------------------------------------------------------------
  147. ' GetWinDirectory
  148. '
  149. ' Returns the Directory in which Windows is installed.        
  150. '--------------------------------------------------------------------------
  151.  
  152.     Dim sBuffer as String * 256: sBuffer = string( 256, " " )
  153.                                                                  
  154.     GetWindowsDirectory sBuffer, 256
  155.  
  156.     GetWinDirectory = sBuffer
  157.  
  158. End Function
  159.  
  160.  
  161. Public Function GetTempDirectory() as String
  162.  
  163. '--------------------------------------------------------------------------
  164. ' GetTempDirectory
  165. '
  166. ' The temporary directory "TEMP" set in the environment variables. 
  167. ' If this fails, it looks for "TMP".  If neither one is found, it returns
  168. ' an empty string.
  169. '--------------------------------------------------------------------------
  170.  
  171.     Dim sTempBuffer as String
  172.     
  173.     sTempBuffer = Environ$( "TEMP" )
  174.  
  175.     If sTempBuffer = "" then
  176.         sTempBuffer = Environ$ ( "TMP" )
  177.     End If
  178.  
  179.     GetTempDirectory = sTempBuffer
  180.  
  181. End Function
  182.  
  183.  
  184. Public Function WindowsHelp(HelpFile as String, HelpType as Integer ) as Long
  185.  
  186. '--------------------------------------------------------------------------
  187. ' WindowsHelp
  188. '
  189. ' Brings up Windows Help with a given help file and context flags.
  190. '--------------------------------------------------------------------------
  191.  
  192.    WindowsHelp = WinHelp(0, HelpFile, HelpType, 0 )
  193.  
  194. End Function 
  195.  
  196.  
  197. Public Function GetProfInteger(Section as String, Entry as String, Filename as String, DefaultValue as Integer) as Long
  198.         
  199. '--------------------------------------------------------------------------
  200. ' GetProfInteger
  201. '
  202. ' Finds a value of the specified entry in the specified file.  If
  203. ' the entry is not found, the return value is set to zero.
  204. '--------------------------------------------------------------------------
  205.  
  206.     Dim retval as Integer
  207.  
  208.     If filename = "" then
  209.         retval = GetProfileInt(Section, Entry, DefaultValue)
  210.     Else
  211.         retval = GetPrivateProfileInt(Section, Entry, DefaultValue, Filename)
  212.     End If
  213.  
  214.     GetProfInteger = retval
  215.  
  216. End Function
  217.  
  218.  
  219. Public Function GetProfString(Section as String, Entry as String, Filename as String, DString as String) as String
  220.  
  221. '--------------------------------------------------------------------------
  222. ' GetProfString
  223. '
  224. ' This function returns a profile string from the specified ini file.
  225. ' If the filename passed is "", then the string will be searched for
  226. ' in the WIN.INI file
  227. '--------------------------------------------------------------------------
  228.  
  229.     Dim retstr as String*256
  230.     Dim retval as Integer
  231.  
  232.     If filename = "" then
  233.         retval = GetProfileString(Section, Entry, DString, retstr, 256)
  234.    Else
  235.         retval = GetPrivateProfileString(Section, Entry, DString, retstr, 256,Filename)
  236.     End If
  237.             
  238.     GetProfString = Left$(retstr, retval)
  239.  
  240. End Function
  241.  
  242.  
  243. Public Function WriteProfInteger(Section as String, Entry as String, Filename as String, NewValue as Integer) as Long
  244.     
  245. '--------------------------------------------------------------------------
  246. ' WriteProfInteger
  247. '--------------------------------------------------------------------------
  248.  
  249.     Dim Strval as String
  250.     Dim Errval as Integer
  251.     Dim CurrChar as String
  252.  
  253.     Strval = CSTR(NewValue)
  254.     
  255.     If filename = "" then
  256.         Errval = WriteProfileString(Section, Entry, Strval)
  257.     Else
  258.         Errval = WritePrivateProfileString(Section, Entry, Strval, Filename)
  259.     End if
  260.     
  261.     WriteProfInteger = Errval
  262.                             
  263. End Function
  264.  
  265.  
  266. Public Function WriteProfString(Section as String, Entry as String, Filename as String, NewString as String ) as Long
  267.  
  268. '--------------------------------------------------------------------------
  269. ' WriteProfString
  270. '--------------------------------------------------------------------------
  271.  
  272.     Dim Errval as Integer
  273.     
  274.     If filename = "" then
  275.         Errval = WriteProfileString(Section, Entry, NewString)
  276.     Else
  277.         Errval = WritePrivateProfileString(Section, Entry, NewString, Filename)
  278.     End If
  279.     
  280.     WriteProfString = Errval        
  281.  
  282. End Function
  283.  
  284. public function AppClose(AppName as String) as Long
  285.  
  286. '--------------------------------------------------------------------------
  287. ' AppClose
  288. '
  289. ' Close a particular application
  290. '--------------------------------------------------------------------------
  291.  
  292.     on error goto handleit
  293.  
  294.     ActivateApp AppName
  295.     SendKeys "%{F4}", TRUE
  296.     AppClose = TRUE
  297.     exit function
  298.  
  299.     handleit:
  300.         AppClose = FALSE
  301.  
  302. end function
  303.  
  304.  
  305. public function AppGetAppCount() as Long
  306.  
  307. '--------------------------------------------------------------------------
  308. ' AppGetAppCount
  309. '
  310. ' Return number of running Windows applications
  311. '--------------------------------------------------------------------------
  312.  
  313.     dim hWnd as Long
  314.     dim namebuf as string*80
  315.     dim textlen as Integer
  316.  
  317.     AppGetAppCount = 0
  318.     hWnd = GetWindow(GetDesktopWindow(),GW_CHILD)
  319.     
  320.     do while hWnd <> 0
  321.  
  322.         textlen = GetWindowText(hWnd,namebuf,80)
  323.         if textlen <> 0 then
  324.             AppGetAppCount = AppGetAppCount + 1
  325.         end if
  326.  
  327.         hWnd = GetNextWindow( hWnd, GW_HWNDNEXT )
  328.      
  329.     loop
  330.  
  331. end function
  332.  
  333.  
  334. public function AppGetAppNames(AppList() as String, AppCount as Integer) as Integer
  335.  
  336. '--------------------------------------------------------------------------
  337. ' AppGetAppNames
  338. '
  339. ' Fill an array with the names of the currently running applications.
  340. '--------------------------------------------------------------------------
  341.  
  342.     dim hWnd as Long
  343.     dim namebuf as String*80 ': namebuf = string(80," ")
  344.     dim i as Integer : i = 0
  345.     dim textlen as Integer
  346.  
  347.     redim AppList(AppCount)
  348.  
  349.     hWnd = GetWindow(GetDesktopWindow(),GW_CHILD)
  350.  
  351.     do while hWnd <> 0
  352.  
  353.         textlen = GetWindowText(hWnd,namebuf,80)
  354.  
  355.         if textlen <> 0 then
  356.             AppList(i) = left$(namebuf,textlen) : i = i + 1
  357.             if  i = AppCount then
  358.                 exit do
  359.             end if
  360.         end if
  361.  
  362.         hWnd = GetNextWindow( hWnd, GW_HWNDNEXT )
  363.      
  364.     loop
  365.  
  366.     AppGetAppNames = i
  367.  
  368. end function
  369.  
  370.  
  371. public function AppGetHWnd(AppName as String) as Long
  372.  
  373. '--------------------------------------------------------------------------
  374. ' AppGetHWnd
  375. '
  376. ' Returns HWnd for a given window title
  377. '--------------------------------------------------------------------------
  378.  
  379.     dim hWnd as Long
  380.     dim namebuf as String*80 ': namebuf = string(80," ")
  381.     dim textlen as Integer
  382.     
  383.     AppGetHWnd = 0
  384.  
  385.     hWnd = GetWindow(GetDesktopWindow(), GW_CHILD)
  386.  
  387.     if hWnd = 0 then
  388.         AppGetHWnd = 0
  389.         exit function
  390.     end if
  391.  
  392.     do while hWnd <> 0
  393.  
  394.         textlen = GetWindowText(hWnd,namebuf,80)
  395.         if textlen <> 0 then
  396.             if AppName = left$(namebuf,textlen) then
  397.                 AppGetHWnd = hWnd
  398.                 exit do
  399.             end if
  400.         end if
  401.  
  402.         hWnd = GetNextWindow( hWnd, GW_HWNDNEXT )
  403.      
  404.     loop
  405.  
  406. end function
  407.  
  408.  
  409. public function AppGetWindowPos(AppName as String, x as Integer, y as Integer, w as Integer, h as Integer) as Long
  410.  
  411. '--------------------------------------------------------------------------
  412. ' AppGetWindowPos
  413. '
  414. ' Get the coordinates and size of a window
  415. '--------------------------------------------------------------------------
  416.  
  417.     dim hWnd as Long
  418.     dim namebuf as string*80
  419.     dim r as RECT
  420.  
  421.     hWnd = AppGetHWnd(AppName)
  422.  
  423.     if hWnd = 0 then
  424.         AppGetWindowPos = FALSE
  425.         exit function
  426.     end if
  427.         
  428.     ' Window is valid, get rectange coordinates and compute width/height...
  429.  
  430.     call GetWindowRect(hWnd, r)
  431.  
  432.     x = r.left
  433.     y = r.right
  434.     w = r.right - r.left
  435.     h = r.bottom - r.top
  436.     AppGetWindowPos = TRUE
  437.  
  438. end function
  439.  
  440.  
  441. function SetWindowState(AppName as String, NewState as Integer) as Long
  442.  
  443. '--------------------------------------------------------------------------
  444. ' SetWindowState (Private function)
  445. ' Set the state of a named window
  446. '--------------------------------------------------------------------------
  447.  
  448.     dim hWnd as Long
  449.  
  450.     hWnd = AppGetHWnd(AppName)
  451.  
  452.     if hWnd = 0 then
  453.         SetWindowState = FALSE
  454.         exit function
  455.     end if
  456.  
  457.     if ShowWindow(hWnd, NewState) = 0 then
  458.         SetWindowState = TRUE  ' Previously visible
  459.     else
  460.         SetWindowState = FALSE ' Previously hidden
  461.     end if
  462.  
  463. end function
  464.  
  465.  
  466.  
  467. public function AppHide(AppName as String) as Long
  468.  
  469. '--------------------------------------------------------------------------
  470. ' AppHide
  471. '
  472. ' Hides a window
  473. '--------------------------------------------------------------------------
  474.  
  475.     AppHide = SetWindowState(AppName, SW_HIDE)
  476.  
  477. end function
  478.  
  479.  
  480. public function AppShow(AppName as String) as Long
  481.  
  482. '--------------------------------------------------------------------------
  483. ' AppShow
  484. '
  485. ' Shows a window
  486. '--------------------------------------------------------------------------
  487.  
  488.     AppShow = SetWindowState(AppName, SW_SHOW)
  489.  
  490. end function
  491.  
  492.  
  493. public function AppIsRunning(AppName as String) as Long
  494.  
  495. '--------------------------------------------------------------------------
  496. ' AppIsRunning
  497. '
  498. ' Return whether or not an application is running
  499. '--------------------------------------------------------------------------
  500.  
  501.     if AppGetHWnd(AppName) <> 0 then
  502.         AppIsRunning = TRUE
  503.     else
  504.         AppIsRunning = FALSE
  505.     end if
  506.  
  507. end function
  508.  
  509.  
  510. public function AppIsVisible(AppName as String) as Long
  511.  
  512. '--------------------------------------------------------------------------
  513. ' AppIsVisible
  514. '
  515. ' Return whether or not an application is visible
  516. '--------------------------------------------------------------------------
  517.  
  518.     dim hWnd as Long
  519.     
  520.     AppIsVisible = FALSE
  521.  
  522.     hWnd = AppGetHWnd(AppName)
  523.     if hWnd <> 0 then
  524.         if IsWindowVisible(hWnd) then
  525.             AppIsVisible = TRUE
  526.         end if
  527.     end if
  528.  
  529. end function
  530.  
  531.  
  532. public function AppMaximize(AppName as String) as Long
  533.  
  534. '--------------------------------------------------------------------------
  535. ' AppMaximize
  536. ' Maximizes a window
  537. '--------------------------------------------------------------------------
  538.  
  539.     AppMaximize = SetWindowState(AppName, SW_MAXIMIZE)
  540.  
  541. end function
  542.  
  543.  
  544. public function AppMinimize(AppName as String) as Long
  545.  
  546. '--------------------------------------------------------------------------
  547. ' AppMinimize
  548. ' Minimizes a window
  549. '--------------------------------------------------------------------------
  550.  
  551.     AppMinimize = SetWindowState(AppName, SW_MINIMIZE)
  552.  
  553. end function
  554.  
  555.  
  556. public function AppRestore(AppName as String) as Long
  557.  
  558. '--------------------------------------------------------------------------
  559. ' AppRestore
  560. ' Restore window to previous state
  561. '--------------------------------------------------------------------------
  562.  
  563.     AppRestore = SetWindowState(AppName, SW_RESTORE)
  564.  
  565. end function
  566.  
  567.  
  568. public function AppMove(AppName as String, x as Integer, y as Integer) as Long
  569.  
  570. '--------------------------------------------------------------------------
  571. ' AppMove
  572. '
  573. ' Move a window
  574. '--------------------------------------------------------------------------
  575.  
  576.     dim hWnd as Long
  577.  
  578.     hWnd = AppGetHWnd(AppName)
  579.  
  580.     if hWnd = 0 then
  581.         AppMove = FALSE
  582.         exit function
  583.     end if
  584.  
  585.     AppMove = SetWindowPos(hWnd, 0, x, y, 0, 0, SWP_NOSIZE+SWP_NOZORDER)
  586.  
  587. end function
  588.  
  589.  
  590. public function AppSize(AppName as String, w as Integer, h as Integer) as Long
  591.  
  592. '--------------------------------------------------------------------------
  593. ' AppSize
  594. '
  595. ' Resize a window
  596. '--------------------------------------------------------------------------
  597.  
  598.     dim hWnd as Long
  599.  
  600.     hWnd = AppGetHWnd(AppName)
  601.  
  602.     if hWnd = 0 then
  603.         AppSize = FALSE
  604.         exit function
  605.     end if
  606.  
  607.     AppSize = SetWindowPos(hWnd, 0, 0, 0, w, h, SWP_NOMOVE+SWP_NOZORDER)
  608.  
  609. end function
  610.  
  611.  
  612. public function AppSendMessage(AppName as String, msg as Integer, wParam as Integer, lParam as Long) as Long
  613.  
  614. '--------------------------------------------------------------------------
  615. ' AppSendMessage
  616. ' Send a Windows message to a window
  617. '--------------------------------------------------------------------------
  618.  
  619.     dim hWnd as Long
  620.  
  621.     hWnd = AppGetHWnd(AppName)
  622.  
  623.     if hWnd = 0 then
  624.         AppSendMessage = FALSE
  625.         exit function
  626.     end if
  627.  
  628.     AppSendMessage = SendMessage(hWnd, msg, wParam, lParam)
  629.  
  630. end function
  631.  
  632.  
  633.  
  634. Public Function FormatDate(d as variant, fmt as string) as string
  635.  
  636. '--------------------------------------------------------------------------
  637. ' FormatDate
  638. '
  639. ' Formats date based on specified flag.
  640. '--------------------------------------------------------------------------
  641.  
  642.     select case fmt
  643.  
  644.         case is="b":     FormatDate =    format$(d, "mmmm dd, yyyy")
  645.         case is="B":     FormatDate =     ucase(format$(d, "mmmm dd, yyyy"))
  646.         case is="c":     FormatDate =    format$(d, "dd mmmm yyyy")
  647.         case is="C":    FormatDate =     ucase(format$(d, "dd mmmm yyyy"))
  648.         case is="d":    FormatDate =    format$(d, "long date")
  649.         case is="D":    FormatDate =    ucase(format$(d, "long date"))
  650.         case is="e":    FormatDate =    format$(d, "mmmm dd")
  651.         case is="E":    FormatDate =    ucase(format$(d, "mmmm dd"))
  652.         case is="f":     FormatDate =    format$(d, "dddd dd")
  653.         case is="F":    FormatDate =     ucase(format$(d, "dddd dd"))
  654.         case is="g":    FormatDate =    format$(d, "mm/dd")
  655.         case is="G":    FormatDate =    ucase(format$(d, "mm/dd"))
  656.         case is="h":    FormatDate =    format$(d, "mm/dd/yyyy")
  657.         case is="H":    FormatDate =    ucase(format$(d, "mm/dd/yyyy"))
  658.         case is="i":     FormatDate =    format$(d, "dd, mmmm")
  659.         case is="I":     FormatDate =    ucase(format$(d, "dd, mmmm"))
  660.         case is="j":    FormatDate =    format$(d, "dd, mmmm yyyy")
  661.         case is="J":    FormatDate =    ucase(format$(d, "dd, mmmm yyyy"))
  662.         case is="k":    FormatDate =    format$(d, "yyyy mmmm dd")
  663.         case is="K":    FormatDate =     ucase(format$(d, "yyyy mmmm dd"))
  664.         case is="l":     FormatDate =    format$(d, "mmmm, dd")
  665.         case is="L":    FormatDate =     ucase(format$(d, "mmmm, dd"))
  666.         case else:        FormatDate =    ""
  667.     end select
  668.  
  669. End function
  670.  
  671.  
  672. Public Function DateDiff(date1 as Variant, date2 as Variant ) as Long
  673.  
  674. '--------------------------------------------------------------------------
  675. ' DateDiff
  676. '
  677. ' Returns an integer value that represents the number of days that
  678. ' separate the dates passed to the function
  679. '--------------------------------------------------------------------------
  680.  
  681.     Dim TempVal as Variant
  682.  
  683.     TempVal = CINT((DateValue(date1)) - (DateValue(date2)) )
  684.  
  685.     DateDiff = ABS(TempVal)
  686.  
  687. End Function
  688.  
  689.  
  690. Public Sub Pause( pausetime as Integer ) 
  691.  
  692. '--------------------------------------------------------------------------
  693. ' Pause
  694. '
  695. ' Suspend execution of application for specified amount of time.
  696. '--------------------------------------------------------------------------
  697.  
  698.     Dim BeginTime as Single
  699.  
  700.     BeginTime = Timer
  701.  
  702.     Do While Timer < BeginTime + pausetime
  703.         Yield
  704.     loop
  705.  
  706. End Sub
  707.  
  708.  
  709. Public Function ProperCase ( s as String ) as String
  710.  
  711. '----------------------------------------------------------------------------
  712. ' ProperCase
  713. '
  714. ' Capitalizes the first character, and lowercases the rest, of a string.
  715. '----------------------------------------------------------------------------
  716.  
  717.     Dim UpperIt as Integer : UpperIt = TRUE
  718.     Dim newstring as string 
  719.     Dim currchar as string
  720.     Dim i as Integer
  721.  
  722.     For i = 1 to len(s) 
  723.         currchar = mid(s,i,1)
  724.         currchar = lcase$(currchar)
  725.         If UpperIt then
  726.             currchar = ucase$(currchar)
  727.             UpperIt = FALSE
  728.         End if
  729.         If currchar = " " then
  730.             UpperIt = TRUE
  731.         End if
  732.         newstring = newstring + currchar
  733.     Next i
  734.  
  735.     ProperCase = newstring
  736.  
  737. End Function
  738.  
  739.  
  740. Public Function Repeat(pattern as string, repcount as integer, maxlen as integer) as String
  741.  
  742. '----------------------------------------------------------------------------
  743. ' Repeat
  744. '
  745. ' Repeat a given pattern a certain number of times, up to a maximum length.
  746. '----------------------------------------------------------------------------
  747.  
  748.     Dim Newstring as String 
  749.    Dim i as Integer
  750.  
  751.     For i =  1 to repcount
  752.         Newstring = Newstring + pattern
  753.     Next i
  754.  
  755.     If maxlen <> 0 then ' in lieu of ommitted arguments...
  756.         newstring = left$(newstring, maxlen)
  757.     end if
  758.  
  759.     Repeat = newstring
  760.  
  761. End function    
  762.  
  763.  
  764. Public Function Str_Word(searchstr as String, sepstr as String, wordnum as Integer) as String
  765.  
  766. '----------------------------------------------------------------------------
  767. ' Str_Word
  768. '
  769. ' Search for a given numbered repetition of a substring
  770. '----------------------------------------------------------------------------
  771.  
  772.     Dim done as Integer : done = FALSE
  773.     Dim beginpos as Integer : beginpos = 0
  774.     Dim endpos as Integer : endpos = 0
  775.    Dim i as Integer
  776.  
  777.     For i = 1 to wordnum
  778.         beginpos = endpos + 1
  779.         endpos = instr(beginpos, searchstr, sepstr)
  780.         if endpos = 0 then
  781.             endpos = len(searchstr) + 1
  782.             exit for
  783.         end if
  784.     Next i
  785.  
  786.     Str_Word = mid$(searchstr,beginpos,endpos-beginpos)
  787.  
  788. End function
  789.  
  790.  
  791. Public Function Log10( inVal as Double) as Double
  792.  
  793. '----------------------------------------------------------------------------
  794. ' Log10
  795. '
  796. ' Calculates the logarithm for a given number for the base of 10.
  797. '----------------------------------------------------------------------------
  798.  
  799.     Log10 = Log(inVal)/Log(10)
  800.  
  801. End function    
  802.  
  803.